package com.durian.app;

import android.app.Application;
import android.content.ComponentCallbacks2;
import android.content.res.Configuration;
import com.durian.BaseApp;
import com.durian.app.lifecycle.api.AppLifeCycleManager;

/**
 * 说明：DurianApp
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-08-14 15:49
 * <p/>
 * 版本：version 1.0
 */
public class Durian {

    private static boolean isInit = false;

    public static void init(Application application, boolean isDebug) {
        if (isInit){
            return;
        }
        isInit = true;
        if (application == null) {
            throw new RuntimeException("application is null!!!");
        }
        BaseApp.setDebug(isDebug);
        AppLifeCycleManager.init(application);
        application.registerComponentCallbacks(new ComponentCallbacks2() {
            @Override
            public void onTrimMemory(int level) {
                AppLifeCycleManager.terminate();
            }

            @Override
            public void onConfigurationChanged(Configuration newConfig) {

            }

            @Override
            public void onLowMemory() {
                AppLifeCycleManager.lowMemory();
            }
        });
    }
}